package org.example.code.test2024.eleven;

import java.util.*;

/**
 * @Title: test1122
 * @Author yxy
 * @Package org.example.code.eleven
 * @Date 2024/11/22 11:34
 * @description:
 */
public class test1122 {

    public int missingNumber(int[] nums) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < nums.length; i++) {
            list.add(nums[i]);
        }
        for (int i = 0; i <= nums.length; i++) {
            if(!list.contains(i)) {
                return i;
            }
        }
        return -1;
    }



    public int findPeakElement(int[] nums) {
        int low = 0, high = nums.length-1;
        while(low<high){
            int mid = (low + high)/2;
            if(nums[mid]<nums[mid+1]){
                low = mid+1;
            }else{
                high = mid;
            }
        }
        return low;
    }


    public int[] findRightInterval(int[][] intervals) {
        int[] result = new int[intervals.length];
        Arrays.fill(result,-1);
        for(int i = 0; i < intervals.length; i++){
            int min = Integer.MAX_VALUE;
            for(int j = 0; j < intervals.length; j++){
                if(intervals[j][0]>=intervals[i][1]){
                    if(intervals[j][0]<min){
                        min = intervals[j][0];
                        result[i] = j;
                    }
                }
            }
        }
        return result;
    }

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<Integer>();
        for(int i = 0; i < nums1.length; i++){
            for(int j = 0; j < nums2.length; j++){
                if(nums1[i]==nums2[j]){
                    set.add(nums1[i]);
                }
            }
        }
        return set.stream().mapToInt(i->i).toArray();
    }

    //    [[3,4],[2,3],[1,2]]
    public static void main(String[] args) {
        int[] num1 = {1,1,2,2,2};
        int[] num2 = {2};
        test1122 test = new test1122();
        int[] rightInterval = test.intersection(num1,num2);
        for(int i = 0; i < rightInterval.length; i++){
            System.out.println(rightInterval[i]);
        }
    }

}
